<!--
        Copyright (c) 2023, LXMS (lxinet.cn).

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<template>
  <lx-search-bar :searchConfig="searchConfig" v-model:queryParams="queryParams" @onSearch="handleSearch"></lx-search-bar>
  <div class="containerBox">
    <lx-table
        ref="listTable"
        selectionType="none"
        v-model:selectedRowKeys="selectedRowKeys"
        :rowKey="rowKey"
        :url="url.list"
        :autoLoad="false"
        :loading="loading"
        :ltTools="ltTools"
        :columns="columns"
        :hasPagination="true"
        :params="{...queryParams}"
        @handleToolsClick="handleToolsClick"
    >
      <template #loginType="{row}">
        <a-tag v-if="row.loginType === 0" color="green">账号密码登录</a-tag>
        <a-tag v-if="row.loginType === 1" color="cyan">手机号密码登录</a-tag>
        <a-tag v-if="row.loginType === 2" color="blue">手机号验证码登录</a-tag>
      </template>
      <template #status="{row}">
        <a-tag v-if="row.status === 0" color="red">登录失败</a-tag>
        <a-tag v-else color="green">登录成功</a-tag>
      </template>
      <template #action="{row}">
        <a-button @click="handleAction('detailNode','detail',row)" size="small" type="link" v-has="'sys:loginLog:detail'">详情</a-button>
      </template>
    </lx-table>
  </div>
  <detail ref="detailNode"></detail>
</template>

<script>
import lxSearchBar from "@components/baseComponents/lxSearchBar/index.vue"
import lxTable from "@components/baseComponents/lxTable/index.vue"
import detail from "./detail.vue"
import {indexPageMinxin} from "@/minxins/indexPageMinxin"

export default {
  name: "systemPost",
  components: {
    lxSearchBar,
    lxTable,
    detail,
  },
  mixins: [indexPageMinxin],
  data() {
    return {
      url: {
        list: "/system/loginLog/list",
      },
      columns: [
        {
          title: "登录账号",
          key: "account",
          width: 150,
          align: "center",
        },
        {
          title: "登录类型",
          key: "loginType",
          width: 100,
          align: "center",
          render: "loginType"
        },
        {
          title: "登录IP",
          key: "ip",
          width: 150,
          align: "center",
        },
        {
          title: "操作系统",
          key: "os",
          width: 100,
          align: "center",
        },
        {
          title: "浏览器",
          key: "userAgent",
          align: "center",
        },
        {
          title: "登录结果",
          key: "status",
          width: 80,
          align: "center",
          render: "status"
        },
        {
          title: "登录时间",
          key: "createTime",
          width: 150,
          align: "center",
        },
        {
          title: "操作",
          key: "handle",
          width: 80,
          fixed: "right",
          align: "center",
          render: "action",
        },
      ],
      searchConfig: [
        {
          component: "a-input",
          key: "name",
          title: "登录账号",
          props: {
            allowClear: true
          }
        },
        {
          component: "a-input",
          key: "code",
          title: "登录IP",
          props: {
            allowClear: true
          }
        },
      ],
    };
  },
  mounted() {
    this.getList();

  },
  methods: {
    getList() {
      this.loading = true;
      this.$nextTick(() => {
        this.$refs.listTable.loadData(1);
      })
      this.loading = false;

    },

  }
}
</script>

<style scoped>

</style>